<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">
<ui:composition template="template.xhtml">
	<ui:define name="content">
		<h:form id="form01">
			<f:metadata>
				<f:event type="preRenderView" oncomplete="PF('widgetVar_w').clearFilters();"
					listener="#{medicineListControler.onPageLoad}" />
			</f:metadata>
			<p:panel
				header="#{dictionaryControler.dictionary['Medicine']} #{dictionaryControler.dictionary['List']}"
				style="text-align:center"
				rendered="#{mainMenuControler.hasUserRole('admin') || mainMenuControler.hasUserRole('medicine')}">
				<div style="float: left">
					<p:commandButton id="addNewBtn" ajax="true"
						value="#{dictionaryControler.dictionary['Add']} #{dictionaryControler.dictionary['Medicine']}"
						actionListener="#{medicineListControler.startAddMedicine}"
						icon="ui-icon-plus" update=":form04:detailDialog" />
				</div>
				<br />
				<br />
				<br />
				<p:messages id="message" />
				<p:dataTable id="medicineTable" widgetVar="widgetVar_w"
					value="#{medicineListControler.medicineList}" var="medicine"
					rows="15" paginator="true" paginatorAlwaysVisible="true"
					filteredValue="#{medicineListControler.filteredTerms}"
					paginatorPosition="bottom" first="#{medicineListControler.first}"
					paginatorTemplate="{PreviousPageLink} {CurrentPageReport} {NextPageLink}">
					<p:column style="width:10%" filterBy="#{medicine.name}"
						filterMatchMode="contains"
						headerText="#{dictionaryControler.dictionary['Name']}">
						<h:outputText value="#{medicine.name}" />
					</p:column>
					<p:column style="width:10%" filterBy="#{medicine.genericNumber}"
						filterMatchMode="contains"
						headerText="#{dictionaryControler.dictionary['Generic Number']}">
						<h:outputText value="#{medicine.genericNumber}" />
					</p:column>
					<p:column style="width:10%"
						headerText="#{dictionaryControler.dictionary['Note']}">
						<h:outputText value="#{medicine.note}" />
					</p:column>
					<p:column style="width:10%"
						headerText="#{dictionaryControler.dictionary['Price']}">
						<h:outputText value="#{medicine.price}" />
					</p:column>
					<p:column style="width:10%"
						headerText="#{dictionaryControler.dictionary['Quantity']}">
						<h:outputText value="#{medicine.quantity}" />
					</p:column>
					<p:column style="width:3%"
						headerText="#{dictionaryControler.dictionary['Edit']}">
						<p:commandButton id="editButton" update=":form04:detailDialog_1"
							action="#{medicineListControler.startEditMedicine}"
							icon="ui-icon-pencil">
							<f:setPropertyActionListener value="#{medicine}"
								target="#{medicineListControler.selectedMedicine}" />
						</p:commandButton>
					</p:column>
					<p:column style="width:3%"
						headerText="#{dictionaryControler.dictionary['Delete']}">
						<p:commandButton id="deleteButton" ajax="true"
							update=":form01:medicineTable"
							action="#{medicineListControler.deleteMedicine}"
							oncomplete="PF('widgetVar_w').clearFilters();"
							icon="ui-icon-close" style="margin-right:5px">
							<f:setPropertyActionListener value="#{medicine}"
								target="#{medicineListControler.selectedMedicine}" />
							<p:confirm
								header="#{dictionaryControler.dictionary['Confirmation']}"
								message="#{dictionaryControler.dictionary['Are you sure']}?"
								icon="ui-icon-alert" />
						</p:commandButton>
					</p:column>
				</p:dataTable>
			</p:panel>
			<h:outputText value="Access Denied, please contact the administrator"
				rendered="#{!(mainMenuControler.hasUserRole('admin') || mainMenuControler.hasUserRole('medicine'))}"
				style="width:100%; height:50%; text-align:center; font-size:150% !important;position:absolute; margin-left:0; margin-right:0; margin-top:0;margin-bottom:0" />
		</h:form>
	</ui:define>

	<ui:define name="dialog">
		<h:form id="form04">
			<p:dialog id="detailDialog" widgetVar="detailDialog_w"
				showEffect="fade" resizable="false" draggable="true"
				closable="false" visible="#{medicineListControler.addMode}"
				header="#{dictionaryControler.dictionary['Add']} #{dictionaryControler.dictionary['Medicine']}">
				<p:focus context="detailDialog" for="addBtn" />
				<p:panelGrid columns="2">
					<h:outputText value="#{dictionaryControler.dictionary['Name']}" />
					<p:inputText value="#{medicineListControler.newMedicine.name}"
						maxlength="15" required="true"
						rendered="#{medicineListControler.addMode}"
						requiredMessage="#{dictionaryControler.dictionary['Name']} #{dictionaryControler.dictionary['Required']}" />
					<h:outputText
						value="#{dictionaryControler.dictionary['Generic Number']}" />
					<p:inputText
						value="#{medicineListControler.newMedicine.genericNumber}"
						maxlength="15" required="true"
						rendered="#{medicineListControler.addMode}"
						requiredMessage="#{dictionaryControler.dictionary['Generic Number']} #{dictionaryControler.dictionary['Required']}" />
					<h:outputText value="#{dictionaryControler.dictionary['Note']}" />
					<p:inputTextarea rows="5" cols="23"
						value="#{medicineListControler.newMedicine.note}" maxlength="120"
						required="true" rendered="#{medicineListControler.addMode}"
						requiredMessage="#{dictionaryControler.dictionary['Note']} #{dictionaryControler.dictionary['Required']}" />
					<h:outputText value="#{dictionaryControler.dictionary['Price']}" />
					<p:inputText value="#{medicineListControler.newMedicine.price}"
						maxlength="15" required="true"
						rendered="#{medicineListControler.addMode}"
						requiredMessage="#{dictionaryControler.dictionary['Price']} #{dictionaryControler.dictionary['Required']}" />
					<h:outputText value="#{dictionaryControler.dictionary['Quantity']}" />
					<p:inputText value="#{medicineListControler.newMedicine.quantity}"
						maxlength="15" required="true"
						rendered="#{medicineListControler.addMode}"
						requiredMessage="#{dictionaryControler.dictionary['Quantity']} #{dictionaryControler.dictionary['Required']}" />
				</p:panelGrid>
				<br />
				<div style="text-align: right">
					<p:commandButton id="addBtn"
						value="#{dictionaryControler.dictionary['Add']}" ajax="true"
						style="margin-right:5px"
						actionListener="#{medicineListControler.addNewMedicine}"
						update=":form04:detailDialog,:form01:medicineTable"
						oncomplete="PF('widgetVar_w').clearFilters();" />
					<p:commandButton id="cancelBtn"
						value="#{dictionaryControler.dictionary['Cancel']}" ajax="true"
						actionListener="#{medicineListControler.cancelAddMedicine}"
						update="detailDialog" immediate="true" />
				</div>
				<p:messages />
			</p:dialog>
			<p:dialog id="detailDialog_1" widgetVar="detailDialog_e"
				resizable="false" draggable="true" closable="false"
				visible="#{medicineListControler.editMode}"
				header="#{dictionaryControler.dictionary['Medicine Edit']}"
				style="text-align:center">
				<p:panelGrid columns="2">
					<h:outputText value="#{dictionaryControler.dictionary['Name']}" />
					<p:inputText value="#{medicineListControler.selectedMedicine.name}"
						maxlength="15" required="true"
						rendered="#{medicineListControler.editMode}"
						requiredMessage="#{dictionaryControler.dictionary['Name']} #{dictionaryControler.dictionary['Required']}" />
					<h:outputText
						value="#{dictionaryControler.dictionary['Generic Number']}" />
					<p:inputText
						value="#{medicineListControler.selectedMedicine.genericNumber}"
						maxlength="15" required="true"
						rendered="#{medicineListControler.editMode}"
						requiredMessage="#{dictionaryControler.dictionary['Generic Number']} #{dictionaryControler.dictionary['Required']}" />
					<h:outputText value="#{dictionaryControler.dictionary['Note']}" />
					<p:inputTextarea rows="5" cols="23"
						value="#{medicineListControler.selectedMedicine.note}"
						maxlength="120" required="true"
						rendered="#{medicineListControler.editMode}"
						requiredMessage="#{dictionaryControler.dictionary['Note']} #{dictionaryControler.dictionary['Required']}" />
					<h:outputText value="#{dictionaryControler.dictionary['Price']}" />
					<p:inputText
						value="#{medicineListControler.selectedMedicine.price}"
						maxlength="15" required="true"
						rendered="#{medicineListControler.editMode}"
						requiredMessage="#{dictionaryControler.dictionary['Price']} #{dictionaryControler.dictionary['Required']}" />
					<h:outputText value="#{dictionaryControler.dictionary['Quantity']}" />
					<p:inputText
						value="#{medicineListControler.selectedMedicine.quantity}"
						maxlength="15" required="true"
						rendered="#{medicineListControler.editMode}"
						requiredMessage="#{dictionaryControler.dictionary['Quantity']} #{dictionaryControler.dictionary['Required']}" />
				</p:panelGrid>
				<br />
				<div style="text-align: right">
					<p:commandButton id="saveBtn_1"
						value="#{dictionaryControler.dictionary['Save']}" ajax="true"
						style="margin-right:5px"
						action="#{medicineListControler.saveEditMedicine}"
						update=":form01:medicineTable,detailDialog_1" />
					<p:commandButton id="cancelBtn_1"
						value="#{dictionaryControler.dictionary['Cancel']}" ajax="true"
						action="#{medicineListControler.cancelEditMedicine}"
						immediate="true" update="detailDialog_1" />
				</div>
				<p:messages />
			</p:dialog>
		</h:form>
	</ui:define>
</ui:composition>
</html>




